package comparesions

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
)

// Branch if reference comparison succeeds
type IF_ACMPEQ struct{ base.BranchInstruction }

func (ia *IF_ACMPEQ) Execute(jFrame *rtda.JFrame) {
	if _acmp(jFrame) {
		base.Branch(jFrame, ia.Offset)
	}
}

type IF_ACMPNE struct{ base.BranchInstruction }

func (ia *IF_ACMPNE) Execute(jFrame *rtda.JFrame) {
	if !_acmp(jFrame) {
		base.Branch(jFrame, ia.Offset)
	}
}

func _acmp(jFrame *rtda.JFrame) bool {
	stack := jFrame.OperandStack()
	ref2 := stack.PopRef()
	ref1 := stack.PopRef()
	return ref1 == ref2 // todo
}
